package br.ufmg.dcc.simulesspl.aspect;

import br.ufmg.dcc.simulesspl.i18n.*;
import br.ufmg.dcc.simulesspl.model.*;

public aspect Propaganda 
{
	public String[] propagandas = {
			"Buy BONO: Cookies for Java users.",
			"Lacking fun at work? Play SimulES today! - 555-SMES",
			"Neurologist Johnes: your fix today.",
			"Watch Star Wars!",
			"South Milk - 'Delicious', say Brad Williams",
			"Would love to fire random people from your company, but lack a steel hand? Jack Human Resources 555-JACK.",
			"Watch Michael Jordan today!",
			"Your car can't just go forward? Buy a new car at Jackson's!",
			"Need a pill? Araujo!",
			"If you feel you play too much, you shouldn't stop. Go for it!"
	};
	
	public boolean estaEmIngles = false;
	
	public pointcut sprint() : 
		call(* GameBoard.isOver())
		;

	public pointcut emIngles(): within(EnglishGameI18N);
	
	public pointcut emPortugues(): within(PortugueseGameI18N);
	
	before(): 
		emIngles()
		{
			estaEmIngles = true;
		}
	
	before():
		emPortugues()
		{
			estaEmIngles = false;
		}
	
	after(): 
		sprint()
		{
			if(estaEmIngles)
				System.out.println("AVERTISING:".concat(propagandaAleatoria()));
		}
	
	String propagandaAleatoria()
	{
		double rand = Math.random();
		double intervalo = 1.0/propagandas.length;
		rand = rand / intervalo;
		int qual = ((int) rand) % propagandas.length;
		
		return propagandas[qual];
	}
}
